package com.qf.spring.service.impl;

import com.qf.spring.dao.UserDao;
import com.qf.spring.dao.impl.UserDaoImpl;
import com.qf.spring.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

@Service//告诉spring帮我们创建这个对象,Service为Component注解的一个别名，方便区分当前类是干什么的
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)//多例的
public class UserServiceImpl implements UserService {
    private UserDao userDao;
    @Autowired//告诉spring帮我们自动设置这个属性
    @Qualifier("1")
    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }
    @Override
    public void addService() {
        System.out.println("service-----------------------");
        userDao.add();
    }
    @PostConstruct
    public void init(){
        System.out.println("init执行了----------------");
    }
    @PreDestroy
    public void destory(){
        System.out.println("destory执行了--------------");
    }
}
